//
//  MyWeather.m
//  Ghac 4S
//
//  Created by apple on 11-12-8.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//
#import "Global.h"
#import "MyWeather.h"
#import <MapKit/MapKit.h>
@interface MyWeather(private)
//-(void)queryEvent:(id)sender;

@end

@implementation MyWeather
@synthesize templeture;
@synthesize weatherImage;
-(id)initWithDelegate:(id<WeatherDelegate>)delegate
{
    if ((self = [super init]))
    {
        KRELEASE(m_delegate);
        m_delegate = [delegate retain];
        m_timer = [[NSTimer timerWithTimeInterval:3600 target:self selector:@selector(queryEvent:) userInfo:nil repeats:YES] retain];
        [[NSRunLoop currentRunLoop] addTimer:m_timer forMode:NSRunLoopCommonModes];
        [self queryEvent:nil];
    }
    return self;
}
-(void)queryEvent:(id)sender
{
    CLLocationManager* locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    [locationManager setDistanceFilter:1000];//update per killmeters
    
#if TARGET_IPHONE_SIMULATOR
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(113.286381, 23.134954);
    [self updateLocationCoordinate:coordinate];
#elif TARGET_OS_IPHONE
    [locationManager startUpdatingLocation];
#endif
}
-(void)errorOnGettingCity:(NSError *)err
{
    NSLog(@"%@", err);
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    [manager stopUpdatingLocation];
    [manager release];
    [self updateLocationCoordinate:newLocation.coordinate];
}
-(void)dealloc
{
    self.templeture = nil;
    self.weatherImage = nil;
    KRELEASE(m_delegate);
    KRELEASE(m_timer);
}
@end
